﻿using Hidistro.Entities.Commodities;
using Hidistro.Membership.Context;
using Hidistro.SaleSystem.Catalog;
using Hidistro.SaleSystem.Comments;
using Hidistro.UI.Common.Controls;
using Hidistro.UI.SaleSystem.Tags;
using System;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace Hidistro.UI.SaleSystem.CodeBehind
{
    public class JuseshangchengTowCategory : HtmlTemplatedWebControl
    {
        
        private HtmlGenericControl htmlp;
        private HtmlGenericControl mbx;
        private Repeater rp;

        protected override void AttachChildControls()
        {
            this.htmlp = (HtmlGenericControl)this.FindControl("p");
            this.mbx = (HtmlGenericControl)this.FindControl("mbx");

            int cid = 0;
            int pages = 1;
            if (this.Page.Request.QueryString["Cid"] != null)
            {
                cid = int.Parse(this.Page.Request.QueryString["Cid"]);
            }
            if (this.Page.Request.QueryString["page"] != null)
            {
                pages = int.Parse(this.Page.Request.QueryString["page"]);
            }
            CategoryInfo category = CategoryBrowser.GetCategoryRewrite(cid);//当前分类
            CategoryInfo categorys = CategoryBrowser.GetCategory(category.ParentCategoryId==null?0:(int)category.ParentCategoryId);//上级分类
            List<CategoryInfo> list = CategoryBrowser.GetMaxSubCategories(categorys.CategoryId, 0x3e8) as List<CategoryInfo>;//同级分类

            this.mbx.InnerHtml = "<a href='/' target=\"_blank\">橘色商城</a>&nbsp;&gt;&nbsp;<a href=\"/juse/index.html\" target=\"_blank\">成人用品</a>&nbsp;&gt;&nbsp;<a href=\"/juse/category-" + categorys.CategoryId + ".htm\">" + categorys.Name + "</a>&nbsp;&gt;&nbsp;<a href=\"/juse/category/plist-" + category.CategoryId + ".htm\"><h1>" + category.Name + "</h1></a>"; ;
            htmlp.InnerHtml = "所有分类： <a href=\"/juse/category-" + categorys.CategoryId + ".htm\">全部商品</a>";
            foreach (CategoryInfo v in list)
            {
                htmlp.InnerHtml += "<a target=\"_blank\" href=\"/juse/category/plist-" + v.CategoryId + ".htm\">" + v.Name + "</a>";
            }
            LoadPageSearch(category);
        }
        private void LoadPageSearch(CategoryInfo category)
        {
            if (!string.IsNullOrEmpty(category.ReviewMeta_Keywords))
            {
                MetaTags.AddMetaKeywords(category.ReviewMeta_Keywords, HiContext.Current.Context);
            }
            if (!string.IsNullOrEmpty(category.ReviewMeta_Description))
            {
                MetaTags.AddMetaDescription(category.ReviewMeta_Description, HiContext.Current.Context);
            }
            if (!string.IsNullOrEmpty(category.ReviewMeta_Title))
            {
                PageTitle.AddSiteNameTitle(category.MetaTitle);
            }
            else
            {
                PageTitle.AddSiteNameTitle(category.Name);
            }
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "/juseshangcheng/Skin-JuseshangchengTowCategory.html";
            }
            base.OnInit(e);
        }
    }
}
